package com.wl.shop.service.impl;

import com.wl.shop.entity.Article;
import com.wl.shop.dao.ArticleDao;
import com.wl.shop.service.ArticleService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wangl
 * @since 2017-05-24
 */
@Service("articleService")
@Transactional(readOnly = true)
public class ArticleServiceImpl extends ServiceImpl<ArticleDao, Article> implements ArticleService {

	@Autowired
	private ArticleDao aticleDao;
	
	@Override
	public void saveOrUpdate(Article article) {
		// TODO Auto-generated method stub
		if(article.getId() != null && article.getId() != 0){
			article.preUpdate();
			updateById(article);
		}else{
			article.preInsert();
			insert(article);
		}
	}

	@Override
	public Integer selectMaxSort(String categoryId) {
		// TODO Auto-generated method stub
		Integer s = aticleDao.selectMaxSort(categoryId);
		return s==null?0:s.intValue();
	}
	
}
